var express = require('express');
var router = express.Router();
var db = require('../db/mysql')
var response = require('../response');
const log4 = require('../log4')

/**
 * @api {post} /log/list 获取用户的备忘录（分页）
 * @apiDescription 获取用户的备忘录（分页）
 * @apiName log-List
 * @apiGroup Log
 * @apiParam {number} pageIndex 当前页
 * @apiParam {number} pageSize 页面尺寸
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "code" : 200,
 *      "data" : []
 *  }
 * @apiSampleRequest http://localhost:3000/log/list
 * @apiVersion 1.0.0
 */
router.post('/list', function(req, res, next) {
  try {
    if (!req.session.user) {
      response.unLogin(res)
      return false
    }
    db.getPage('log', ['*'], {
      belone: req.session.user.uid,
      enable: 1
    }, req.body.pageIndex, req.body.pageSize).then((result) => {
      if (result.length > 0) {
        response.success(res, result)
      } else {
        response.error(res, `获取失败`)
      }
    })
  } catch (error) {
    log4.error(error)
  }
});

module.exports = router;